			
	****************************************************************************
	****************************** HS&B 1980 Sophmore **************************
	****************************************************************************
	/*** The state identifier for the HS&B 1980 is obtained from Joshua Goodman.
	Email: edecjosh@bu.edu
	*/
	clear all
	set more off
	set maxvar 15000
		
	use "C:\Users\EAsker\Desktop\ABR\hsb_80\hsb_80_data\hsb_sophmore.dta" ,clear 
	
	rename *, lower
	
	/*keep Public Schools*/
	keep if schsamp==0
	rename schregn region 
	rename schid sch_id
	rename id stu_id
	
	/*Base year variables: 1: Father's Education 2: Mother's Education 
	3: Family Income 4: Child's Race 5: Child's Gender*/	
	gen survey=1980
	label var survey "Survey Year"
	
	gen wave=2 
	label var wave "Survey time: (2 Years Aft HS)"
	
	rename (bb042  bb039 bb101 race sex bywt ) ///
	(mot_edu fat_edu fam_inc race_by sex_by by_weight)
	
	recode mot_edu (2=0) (3/10=1) (11/98=.) (1=.)
	gen mot_hs=mot_edu>=1 if mot_edu~=.
	recode fat_edu (2=0) (3/10=1) (11/98=.) (1=.)
			
	gen fat_hs=fat_edu>=1 if fat_edu~=.
	recode fam_inc  (1=3500) (2=9500) (3=14000) (4=17500) (5=22500) ///
	(6=31500) (7=42500) (96/98=.)
	
	replace fam_inc=fam_inc*(237/82.4) //multiplying with the deflator
	label var fat_hs "Dummy: 1 if respondent's father graduted from a HS"
	label var mot_hs "Dummy: 1 if respondent's mother graduted from a HS"
	label var fam_inc "Family income adjusted for inflation"
	
	gen white=race_by==5 if race_by~=.
	gen black=race_by==4 if race_by~=.
	gen hispanic=race_by==1 if race_by~=.
	gen oth_race=1  if (race_by==2|race_by==3|race_by==6)&race_by~=.
	replace oth_race=0 if race_by==1|race_by==4|race_by==5
	
	recode sex_by (8=.)
	gen female=sex_by==2 if sex_by~=.
	
	label var white "Dummy: 1 if respondent is a white"
	label var black "Dummy: 1 if respondent is black"
	label var hispanic "Dummy: 1 if respondent is hispanic"
	label var oth_race "Dummy: 1 if respondent is other race"
	label var female "Dummy: 1 if respondent is female"
	
	****************************************************************************
	*	High School Graduation
	recode  ty18 (94/98=.)
	gen high_school=1 if (ty18==1|ty18==2) 
	replace high_school=0 if (ty18==3|ty18==4|ty18==5|ty18==6) 
	replace high_school=egqflag if (high_school==.|high_school==0)&egqflag==1
	label var high_school "Dummy: 1 if repondent has a HS diploma"
	
	*	Postsecondary Education
	recode  psesfe84 (98=.)
	gen post_scndry=1 if psesfe84~=9&psesfe84~=.
	replace post_scndry=0 if psesfe84==9&psesfe84~=.
	label var post_scndry "Dummy: 1 ever attanded PSE institution"
	
	*	Register to Voted
	recode ty56 (6/8=.)
 	gen register_vote=1 if ty56==1
	replace register_vote=0 if ty56==2
	label var register_vote "Vote: Registered to Vote"
	
	*	Volunteer
	recode ty59f (6/8=.)  (2/3=0)
	recode ty59l (6/8=.)  (2/3=0)
	recode ty59a (6/8=.)  (2/3=0)
	
	recode ty59b (6/8=.)  (2/3=0)
	recode ty59c (6/8=.)  (2/3=0)
	recode ty59d (6/8=.)  (2/3=0)
	
	recode ty59e (6/8=.)  (2/3=0)
	recode ty59g (6/8=.)  (2/3=0)
	recode ty59h (6/8=.)  (2/3=0)

	recode ty59i (6/8=.)  (2/3=0)
	recode ty59j (6/8=.)  (2/3=0)
	recode ty59k (6/8=.)  (2/3=0)
	
	egen volunteer=rowmax(ty59a ty59c ty59d ty59f ty59g ty59h ty59i ty59j ty59k ty59l)
	
	gen vltnry_prtcptn=1 if volunteer==1
	replace vltnry_prtcptn=0 if volunteer==0
	
	label var vltnry_prtcptn "Dummy: 1 ever participated in voluntary activities"
	
	keep survey wave stu_id sch_id mot_hs fat_hs white black oth_race ///
	female high_school post_scndry vltnry_prtcptn register_vote pbyses vote 
	
	********************** Merging with Joshua Goodman data
	merge m:1  sch_id using "C:\Users\EAsker\Desktop\ABR\hsb_80\hsb_80_data\josh_good.dta" 
	drop if _merge~=3
	drop _merge
	****************************************************************************
	**** Meadian Family Income by School
	replace pbyses=. if pbyses==-1
	egen median_ses=median(pbyses), by(state sch_id)

	save  "C:\Users\EAsker\Desktop\ABR\hsb_80\hsb_80_clean_data\Round_2_hsb_sophmore.dta" , replace 

	**** Meadian Family Income by School
	replace pbyses=. if pbyses==-1
	egen median_ses=median(pbyses), by(state sch_id)
	
	drop if median_ses==.
	******** Generating Quartiles for HS&B 1980
	
	egen qrdinc80_b= xtile(median_ses), nq(4) by(state)	
	drop if qrdinc80_b==.
	
	gen qr80_1=1 if qrdinc80_b==1
	replace qr80_1=0 if qrdinc80_b~=1
	gen qr80_2=1 if qrdinc80_b==2
	replace qr80_2=0 if qrdinc80_b~=2
	gen qr80_3=1 if qrdinc80_b==3
	replace qr80_3=0 if qrdinc80_b~=3
	gen qr80_4=1 if qrdinc80_b==4
	replace qr80_4=0 if qrdinc80_b~=4
	
	rename state stfips
	gen year=1982 ///The year students graduted
		
	*** Merging School Finance Events
	merge m:1 stfips using "C:\Users\EAsker\Desktop\ABR\data\finance_events.dta" 
		
	drop if _merge~=3
	drop _merge
	
	****************************************************************************
	****************************************************************************
	
	gen fipst=stfips
	sort fipst
	
	********************* Reforms
	
	gen CSFR_BHJ=0
	replace CSFR_BHJ=1 if  (year-CSFR_year_BJH)>0&CSFR_year_BJH~=.
	
	****************** BJH
	
	gen exposure_year_BHJ=year-(CSFR_year_BJH+1)
	gen exposure_year_trend_BHJ=exposure_year_BHJ
	replace exposure_year_trend_BHJ=0 if  exposure_year_BHJ<=0|exposure_year_BHJ==.
	replace exposure_year_BHJ=0 if CSFR_BHJ==0&exposure_year_BHJ==.
	**********
	
	gen dummy_30_20=1 if exposure_year_BHJ>=-30&exposure_year_BHJ<=-20
	replace  dummy_30_20=0 if dummy_30_20==.
	
	gen dummy_20_10=1 if exposure_year_BHJ>=-19&exposure_year_BHJ<=-10
	replace  dummy_20_10=0 if dummy_20_10==.
	
	gen dummy_10_1=1 if exposure_year_BHJ>=-9&exposure_year_BHJ<=-1
	replace  dummy_10_1=0 if dummy_10_1==.
	
	**************************
	gen dummy_10=1 if exposure_year_BHJ>=-30&exposure_year_BHJ<=-10
	replace  dummy_10=0 if dummy_10==.
	
	gen dummy_6=1 if exposure_year_BHJ>=-10&exposure_year_BHJ<=-6
	replace  dummy_6=0 if dummy_6==.
	
	gen dummy_5=1 if exposure_year_BHJ>=-5&exposure_year_BHJ<=-1
	replace  dummy_5=0 if dummy_5==.
	
	gen  qr1_sfr_BHJ=CSFR_BHJ*qr80_1
	gen  qr2_sfr_BHJ=CSFR_BHJ*qr80_2
	gen  qr3_sfr_BHJ=CSFR_BHJ*qr80_3
	gen  qr4_sfr_BHJ=CSFR_BHJ*qr80_4

		**** BHJ
		gen qr1_sfr_exp_trend_BHJ=qr1_sfr_BHJ*exposure_year_trend_BHJ 
		
		gen qr1_sfr_exp_BHJ=qr1_sfr_BHJ*exposure_year_BHJ
		
		gen  exposure_year_BHJ_13=exposure_year_BHJ
		replace exposure_year_BHJ_13=13 if exposure_year_BHJ>13
		gen qr1_sfr_exp_BHJ_13=qr1_sfr_BHJ*exposure_year_BHJ_13
		
		**** Fixed Effects for Quartile
		egen statexsurvey_quartile=concat(fipst survey)
		destring statexsurvey_quartile, replace
		egen quartilexstate=concat(fipst qrdinc80_b)
		destring quartilexstate, replace
		egen quartilexsurvey=concat(survey qrdinc80_b)
		destring quartilexsurvey, replace
	
	save  "C:\Users\EAsker\Desktop\ABR\hsb_80\hsb_80_clean_data\hsb_80", replace 
	
	
	
	

	
	

	
	

	
	
	
	
	
	
	
	
	
	
	